package com.wetao.testrxjava;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.google.gson.internal.LinkedTreeMap;
import com.wetao.testrxjava.bean.JsonA_1;
import com.wetao.testrxjava.bean.JsonA_2;
import com.wetao.testrxjava.dagger.Dagger1Activity;
import com.wetao.testrxjava.rxjava.Person;
import com.wetao.testrxjava.rxjava.Plan;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

import io.reactivex.Notification;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.ObservableSource;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
import io.reactivex.functions.BiConsumer;
import io.reactivex.functions.BiFunction;
import io.reactivex.functions.BooleanSupplier;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.functions.Predicate;
import io.reactivex.observables.GroupedObservable;
import io.reactivex.schedulers.Schedulers;

//OKGO  没有写进去，可以查以下几个网址，很适合下载和上传大文件
//https://www.cnblogs.com/zhujiabin/p/7193071.html
//https://www.jianshu.com/p/6aa5cb272514
//jianshu.com/p/0f9070092fdb


public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private final String TAG = "MainActivity";

    //private String jsonA1 = "{tag: \"tag1\"}";
    //private String jsonA1 = "{tag: \"tag1\", jsonA_2:\"\"}";
    private String jsonA1 = "{tag: \"tag1\", jsonA_2:{name:\"chenyihong\", value:\"30\"}}";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btn_testRxjava = findViewById(R.id.btn_testRxjava);
        btn_testRxjava.setOnClickListener(this);
        Button btn_testRxLifecycle = findViewById(R.id.btn_testRxLifecycle);
        btn_testRxLifecycle.setOnClickListener(this);
        Button btn_testAutoDispose = findViewById(R.id.btn_testAutoDispose);
        btn_testAutoDispose.setOnClickListener(this);
        Button btn_testRxBinding = findViewById(R.id.btn_testRxBinding);
        btn_testRxBinding.setOnClickListener(this);
        Button btn_testRetrofit = findViewById(R.id.btn_testRetrofit);
        btn_testRetrofit.setOnClickListener(this);
        Button btn_testDagger = findViewById(R.id.btn_testDagger);
        btn_testDagger.setOnClickListener(this);
        Button btn_testJson = findViewById(R.id.btn_testJson);
        btn_testJson.setOnClickListener(this);



    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_testRxjava:{
                startActivity(new Intent(this, TestRxJavaActivity.class));
            }break;
            case R.id.btn_testRxLifecycle:{
                startActivity(new Intent(this, TestRxLifecycleActivity.class));
            }break;
            case R.id.btn_testAutoDispose:{
                startActivity(new Intent(this, TestAutoDisposeActivity.class));
            }break;
            case R.id.btn_testRxBinding:{
                startActivity(new Intent(this, TestRxBindingActivity.class));
            }break;
            case R.id.btn_testRetrofit:{
                startActivity(new Intent(this, TestRetrofitActivity.class));
            }break;
            case R.id.btn_testDagger:{
                startActivity(new Intent(this, Dagger1Activity.class));
            }break;
            case R.id.btn_testJson:{
                JsonA_1 jsonA_1 = JsonUtils.fromJson(jsonA1, JsonA_1.class);
                Log.i("Joson:", jsonA_1.toString());
                Object obj = jsonA_1.getJsonA_2();
                if(obj instanceof String) {
                    Log.i("Joson:", "obj instanceof String");
                } else if(obj instanceof JsonA_2) {
                    Log.i("Joson:", "obj instanceof JsonA_2"); //一直不会走这一步
                } else if(obj == null) {
                    Log.i("Joson:", "obj == null");
                } else {
                    String str = obj.toString();
                    Log.i("joson:",  str);
                    if(JsonUtils.isGoodJson(str) && str.contains("name")) {
                        JsonA_2 jsonA_2 = JsonUtils.fromJson(str, JsonA_2.class);
                        Log.i("joson:",  jsonA_2.toString());
                    }
                }

                if(obj instanceof LinkedTreeMap) {
                    LinkedTreeMap map = (LinkedTreeMap) obj;
                    if(map.containsKey("name")) {
                        String str = map.get("name").toString();
                        Log.i("joson:",  str);
                    }
                }
            }break;



        }
    }


}
